package com.minimalist.common.feign.fallback.lindi;

import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.contracttemplatefieldoption.LindiContractTemplateFieldOptionQueryVO;
import com.minimalist.common.entity.lindi.vo.contracttemplatefieldoption.LindiContractTemplateFieldOptionVO;
import com.minimalist.common.feign.client.lindi.LindiContractTemplateFieldOptionFeignClient;
import com.minimalist.common.feign.config.BaseFallbackFactory;
import com.minimalist.common.response.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

/**
 * 林地合同模板字段选项 Feign 客户端降级工厂
 * 使用FallbackFactory可以获取到异常信息，便于问题排查
 *
 * @author minimalist
 */
@Component
public class LindiContractTemplateFieldOptionFeignClientFallbackFactory extends BaseFallbackFactory<LindiContractTemplateFieldOptionFeignClient>{
    private static final Logger log = LoggerFactory.getLogger(LindiContractTemplateFieldOptionFeignClientFallbackFactory.class);


    @Override
    public LindiContractTemplateFieldOptionFeignClient create(Throwable cause){
        return new LindiContractTemplateFieldOptionFeignClient(){
            @Override
            public R<?> addContractTemplateFieldOption(LindiContractTemplateFieldOptionVO contractTemplateFieldOptionVO){
                logServiceUnavailable("添加合同模板字段选项", contractTemplateFieldOptionVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "添加合同模板字段选项失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> deleteContractTemplateFieldOptionByContractTemplateFieldOptionId(
                    Long contractTemplateFieldOptionId){
                logServiceUnavailable("删除合同模板字段选项", contractTemplateFieldOptionId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "删除合同模板字段选项失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> updateContractTemplateFieldOptionByContractTemplateFieldOptionId(
                    LindiContractTemplateFieldOptionVO contractTemplateFieldOptionVO){
                logServiceUnavailable("修改合同模板字段选项", contractTemplateFieldOptionVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "修改合同模板字段选项失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<PageResp<LindiContractTemplateFieldOptionVO>> getPageContractTemplateFieldOptionList(
                    LindiContractTemplateFieldOptionQueryVO queryVO){
                logServiceUnavailable("分页查询合同模板字段选项列表", queryVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "分页查询合同模板字段选项列表失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<LindiContractTemplateFieldOptionVO> getContractTemplateFieldOptionByContractTemplateFieldOptionId(
                    Long contractTemplateFieldOptionId){
                logServiceUnavailable("获取合同模板字段选项详情", contractTemplateFieldOptionId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "获取合同模板字段选项详情失败，服务不可用: " + cause.getMessage());
            }
        };
    }
}
